﻿using UnityEngine;
using UnityEngine.UIElements;

namespace winS.UnityEditor.UIElement
{
    /// <summary>
    /// 只读文本.
    /// 类似 <see cref="Label"/> 但提供更多功能
    /// </summary>
    public class ReadonlyText : TextElement
    {
        internal ReadonlyText()
        {
            style.SetPadding(EditorElementUtility.textPadding);
            style.minHeight = EditorElementUtility.fieldMinHeight;
            style.overflow = Overflow.Hidden;
            style.unityTextAlign = TextAnchor.MiddleLeft;
            style.SetUnityFontDefinition(PackageAssets.FontSet.microsoftYahei);
            style.marginTop = style.marginBottom = EditorElementUtility.defaultMarginVertical;
            style.marginLeft = style.marginRight = EditorElementUtility.defaultMarginHorizontal;
        }

        protected override Vector2 DoMeasure(float desiredWidth, MeasureMode widthMode, float desiredHeight, MeasureMode heightMode)
        {
            //在换行模式并且设置了TextElement的flex-basis属性的情况下,文字区域大小的测量有问题
            //可能没问题?
            //if (style.flexBasis.keyword is not StyleKeyword.Null and not StyleKeyword.Auto)
            //{
            //    if (parent.style.flexDirection == FlexDirection.Row) desiredWidth = style.flexBasis.value.value + (style.paddingLeft.value.value + style.paddingRight.value.value);
            //    else desiredHeight = style.flexBasis.value.value + (style.paddingTop.value.value + style.paddingBottom.value.value);
            //}
            return base.DoMeasure(desiredWidth, widthMode, desiredHeight, heightMode);
        }
    }
}